/** 
 * @Title: IFengDao.java 
 * @Package com.zizo.ifeng.carinfo.dao 
 * @Description: TODO
 * @author HeYan
 * @date 2016年9月1日 下午3:41:47 
 */
package com.zizo.ifeng.carinfo.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.zizo.ifeng.carinfo.bean.IFengCarInfo;
import com.zizo.util.ConnectionPool;

/**
 * @ClassName: CarInfoDaoOfIFeng
 * @Description: TODO
 * @author HeYan
 * @date 2016年9月1日 下午3:41:47
 * 
 */
public class CarInfoDaoOfIFeng {
	private static Connection conn = ConnectionPool.getConnection("core", "root", "", "localhost");

	public void insertCarInfo(IFengCarInfo car) {
		PreparedStatement ps = null;
		String sql = "REPLACE INTO ifeng_core_brand(brand_id,brand_name,oem_name,car_id,car_name) VALUES(?,?,?,?,?)";
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, car.getBrand_id());
			ps.setString(2, car.getBrand_name());
			ps.setString(3, car.getOem_name());
			ps.setInt(4, car.getCar_id());
			ps.setString(5, car.getCar_name());
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public List<String> getIDS() throws Exception {
		List<String> list = new ArrayList<>();
		Statement st = conn.createStatement();
		String sql = "SELECT car_id,car_name FROM ifeng_core_brand order by car_id";
		ResultSet rs = st.executeQuery(sql);
		while (rs.next()) {
			String data = rs.getInt("car_id") + "_" + rs.getString("car_name");
			list.add(data);
		}
		return list;
	}
}
